package Hotel_comment;

import java.text.SimpleDateFormat;
import java.util.Date;

public class Test {
    public static void main(String[] args) throws Exception {
        //字符串转换成Date类型
        String str = "7/1/2017 0:45";
        SimpleDateFormat s1 = new SimpleDateFormat("d/M/yyyy H:mm");
        Date date1 = s1.parse(str);
        System.out.println(date1);

        //Date类型转换成字符串
        Date date2 = new Date();
        SimpleDateFormat s2 = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String time = s2.format(date2);
        System.out.println(time);

        //时间戳转换成字符串
        String time2 = "18620192711";
        SimpleDateFormat s3 = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String time3 = s3.format(Long.parseLong(time2));
        System.out.println(time3);

        //Date转换成时间戳
        Date date3 = new Date();
        long l = date3.getTime();
        System.out.println(l);
    }
}
